<?php

namespace maotool\util;

use maotool\file\FileUtil;

class PackageUtil
{

    public static function read($path = null)
    {
        if (is_null($path)) {
            $path = PathUtil::projectPackagePath();
        }
        return FileUtil::readJson($path);
    }

    public static function write($setting, $path = null)
    {
        if (is_null($path)) {
            $path = PathUtil::projectPackagePath();
        }
        FileUtil::writeJson($path, $setting);
    }

    public static function get($key, $path = null)
    {
        $setting = self::read($path);
        return array_key_exists($key, $setting) ? $setting[$key] : null;
    }

    public static function set($key, $value, $path = null)
    {
        $setting = self::read($path);
        $setting[$key] = $value;
    }

}